package com.hzlx.dao.impl;

import com.hzlx.dao.BaseDao;
import com.hzlx.dao.TBusinessInfoDao;
import com.hzlx.dao.TFoodInfoDao;
import com.hzlx.entity.TBusinessInfo;
import com.hzlx.entity.TFoodInfo;

import java.util.Date;
import java.util.List;

/**
 * @author 86166
 * @version 1.0
 * @description: TODO
 * @date 2023/4/9 22:35
 */
public class TFoodInfoDaoImpl extends BaseDao<TFoodInfo> implements TFoodInfoDao {

    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete * from t_food_info where id=?";
        return executeUpdate(sql, id);
    }

    @Override
    public int insert(TFoodInfo record) {
        String sql = "insert into t_food_info values(?,?,?,?,?,default)";
        return  executeUpdate(sql,null,record.getBusinessId(),record.getName(),record.getPrice(),record.getMent());
    }

    @Override
    public int insertSelective(TFoodInfo record) {
        return 0;
    }

    @Override
    public TFoodInfo selectByPrimaryKey(Integer id) {
        String sql = "select * from t_food_info where id = ?";
        List<TFoodInfo> tFoodInfos = executeQuery(sql, TFoodInfo.class, id);
        TFoodInfo tFoodInfo = null;
        if (tFoodInfos.size()>0){
            for (TFoodInfo foodInfo : tFoodInfos) {
                tFoodInfo = foodInfo;
            }
        }

        return tFoodInfo;
    }

    @Override
    public int updateByPrimaryKeySelective(TFoodInfo record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(TFoodInfo record) {
        String sql = "update t_food_info set business_id=?, name=?,price=?,ment=?,status=? where id=?";
        return executeUpdate(sql,record.getBusinessId(),record.getName(),record.getPrice(),record.getMent(),record.getStatus(),record.getId());
    }

    @Override
    public List<TFoodInfo> selectByUserNameFor(String userName) {
        String sql = "select tfi.id,tfi.business_id,tfi.name,tfi.price,tfi.ment,tfi.status from t_business_info as tbi\n" +
                " inner join t_food_info as tfi on tfi.business_id=tbi.id where tbi.name=?";
        return executeQuery(sql, TFoodInfo.class, userName);
    }
}
